package com.example.controller;

import com.example.api.MailManger;
import com.example.api.RedisApi;
import com.example.pojo.User;
import com.example.util.MD5;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/mail")
public class MailController {
    @Resource
    private RedisApi redisApi;

    @Resource
    private MailManger manger;

    @PostMapping("/getCheckCode")
    public void getCheckCode(@RequestBody User user) {
//        log.info("进入方法getCheckCode:" +user.toString());
//        RestResponse restResponse = new RestResponse();
        int code = MD5.getRandomCode();
//        String message = "您的注册验证码为：" + checkCode;
//        try {
//            mailService.sendSimpleMail(user.getEmail(), "注册验证码", message);
//        } catch (Exception e) {
//            restResponse.setData(e);
//            return restResponse;
//        }
//        restResponse.setData(checkCode);
//        return restResponse;
        manger.placeOrder(user.getUserEmail(),String.valueOf(code));
        redisApi.set("emailCode:"+user.getUserEmail() ,60,String.valueOf(code));

    }
}
